<template>
  <div>
    <div class="title">
      <span><i>1</i>输入找回账号</span>
      <span><i>2</i>回答密保问题</span>
      <span class="active"><i>3</i>重置密码</span>
    </div>
    <div class="box">
      <div class="input-item">
        <label>请输入新密码：</label>
        <input type="text" v-model="answer1" />
      </div>
      <button @click="prev2('step2')">上一步</button>
      <button @click="reset">立即重置</button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      answer1: "",
    };
  },
  props: {
    answer: {
      type: String,
      required: true,
    },
    id: {
      required: true,
    },
  },
  methods: {
    prev2(value) {
      this.$emit("prev2", value);
    },
    async reset() {
      const { data: res } = await axios.post(
        "http://124.223.14.236:3001/api/user/resetPwd",
        {
          id: this.id + "",
          password: this.answer1,
          answer: this.answer,
        }
      );
      console.log(res);
      this.answer1 = "";
      if (res.success === true) {
        alert(res.msg);
      } else {
        alert(res.msg);
      }
    },
  },
};
</script>

<style scoped>
@import url("@/assets/css/index.css");
</style>
